package com.jichangxiu.framework.entity.bo;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.jichangxiu.common.entity.rule.PostRule;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.security.core.GrantedAuthority;

import java.io.Serializable;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class SecurityPost implements GrantedAuthority, Serializable {

    private static final long serialVersionUID = 1L;

    public static final String SECURITY_POST_PREFIX = "POST_";

    private PostRule postRule;

    public String getPostId() {
        return postRule.getPostId();
    }

    public String getPostCode() {
        return postRule.getPostCode();
    }

    public String getPostName() {
        return postRule.getPostName();
    }

    public String getPostScope() {
        return postRule.getPostScope();
    }

    @Override
    @JsonIgnore
    public String getAuthority() {
        String postCode = getPostCode();
        return postCode.startsWith(SECURITY_POST_PREFIX) ? postCode : SECURITY_POST_PREFIX + postCode;
    }

}
 